import { Component, ElementRef, Renderer2, ViewChild } from '@angular/core';
import { NavController, NavParams, ToastController, AlertController, App, DateTime } from 'ionic-angular';
import { Api } from "../../providers/api/api";
import { ListMasterPage } from "../../pages/list-master/list-master";
import { HostListener } from "@angular/compiler/src/core";
import { QueOutput, QueInfo, RowInfo, ColumnInfo, FType, DropdownInfo, TopicResultInfo, ListChildInfo, AnswerLog, TopicInfo, AnswerLogUp, MobileAnswer, MobileAnserChd } from '../../models/quesinfo';
import { IonicStorageModule, Storage } from '@ionic/storage';
import { localbase } from '../../models/localbase';
import { CityDataProvider } from '../../providers/city-data/city-data';
import { wyk } from '../../models/commonfile/wyk';
//获取手机经纬度
import { Geolocation } from '@ionic-native/geolocation';
import { Platform } from 'ionic-angular';
import { AsyncPipe } from '@angular/common';


/**
 * Generated class for the TestComponent component.
 *
 * See https://angular.io/api/core/Component for more info on Angular
 * Components.
 */
// baidu map
declare var BMap;
declare var BMAP_STATUS_SUCCESS;
@Component({
  selector: 'index',
  templateUrl: 'index.html'
})


export class IndexComponent {
  testData: QueOutput = this.navParams.get("resData");
  _dd= this.navParams.get("_dd");


  listRes: string;
  data = {};
  res = [];
  text: string;
  applicationInterval: any; // 计时器
  buttonInterval: any; // 定时器
  Que;
  cityColumns: any[];
  location = { lng: 0, lat: 0 };
  topiclist;
  constructor(public navParams: NavParams,
    private api: Api,
    public toastCtrl: ToastController,
    public navCtrl: NavController,
    public alertCtrl: AlertController,
//获取手机经纬度
    private platform: Platform,
    private geolocation: Geolocation,
    // public el: ElementRef,
    private renderer: Renderer2,
    private app: App,
    public cityDataProvider: CityDataProvider,
    public localbasefun: localbase
  ) {





      // get current position




    // this.text = 'Hello World';
    if(this._dd==0){

this.initopic();
    }else {

      this.geolocation.getCurrentPosition().then((resp) => {
        // resp.coords.latitude
        // resp.coords.longitude
         this.location = { lng: resp.coords.longitude, lat: resp.coords.latitude };
         console.log(22222)
         console.log(this.location)
         var convertor = new BMap.Convertor();
         var pointArr = [];
         pointArr.push(this.location);
         var _thas=this;
         convertor.translate(pointArr, 1, 5,async function(data){
              if(data.status === 0) {
                var marker = new BMap.Marker(data.points[0]);
                _thas.location = { lng: data.points[0].lng, lat: data.points[0].lat };
                await _thas.initopic();
              }
            })
      }).catch((error) => {
        console.log('Error getting location', error);
        alert('定位失败');
      });
    }



    // let geolocation1 = new BMap.Geolocation();
    // geolocation1.getCurrentPosition((r) => {
    //   if (geolocation1.getStatus() == BMAP_STATUS_SUCCESS) {
    //     this.location = { lng: r.point.lng, lat: r.point.lat };
    //     console.log('浏览器定位：您的位置是 ' + r.point.lng + ',' + r.point.lat);
    //   }
    //   else {
    //     alert('定位失败');
    //   }

    // }, { enableHighAccuracy: false })
    // // //console.log(this.testData);

    //去掉底部菜单

    //

  }
  @ViewChild('subt') subt: ElementRef;
  z;
  y;
  tt = false;
  ID;
  _I;
  nextBtnText;
  TimeIcon: string;
  TimeText: string;
  _time;

  receiveDate = 0;
  _timebutton = 6;
  timesub;
  timing;
  show;
  time = [];
  FTextContent10002;
  thisFStartTime;

  initopic() {
    console.log(this.testData.Que);
    this.thisFStartTime = new Date();
    this.cityColumns = this.cityDataProvider.cities;
    let listTopic = this.testData.Que.listTopic;
    //隐藏
    listTopic.forEach((onetopic, index) => {
      if(this._dd!=1){



        onetopic.hasw=0;
      }
      else{
        onetopic.hasw=1;
      }
      onetopic.isComplte = true;
      onetopic.sjyc = false;
      onetopic.FTitleYuan = onetopic.FTitle;
      onetopic.maxmin = "";
      //
      onetopic.lat = this.location.lat.toString();
      onetopic.longitude = this.location.lng.toString();
      onetopic.Address = "";
      switch (onetopic.FType) {
        case "10001": onetopic.typename = "单选题"; break;
        case "10002": onetopic.typename = "多选题"; break;
        case "10003": onetopic.typename = "填空题"; break;
        case "10004": onetopic.typename = "主观题"; break;
        case "10005": onetopic.typename = "矩阵题"; break;
        case "10006": onetopic.typename = "打分题"; break;
        case "10007": onetopic.typename = "地区题"; break;
        case "10010": onetopic.typename = "时间题"; break;
        case "10011": onetopic.typename = "排序题"; break;
        case "10012": onetopic.typename = "投票题"; break;
        case "10013": onetopic.typename = "图片题"; break;
        case "10015": onetopic.typename = "下拉题"; break;
        case "10016": onetopic.typename = "比重题"; break;
        case "10017": onetopic.typename = "联动题"; break;
        case "10018": onetopic.typename = "测试选择题"; break;
        case "10020": onetopic.typename = "测试填空题"; break;
        case "30012": onetopic.typename = "行业题"; break;
        case "30014": onetopic.typename = "地图题"; break;
        default: onetopic.typename = "单选题";
      }
      //隐藏
      if (onetopic.FycOpt != null && onetopic.FycOpt != "") {
        onetopic.FShow = false;
      }
      else {
        onetopic.FShow = true;
      }
      //保存多媒体

    })
    //随机筛选
    this.ini10008();
    //
    this.testData.Que.listTopic.forEach((onetopic, index) => {
      // onetopic.FTitleYuan=onetopic.FTitle;
      //
      onetopic.FImage = "";
      onetopic.FAudio = "";
      //
      switch (onetopic.FType) {
        case "10001":
          onetopic.TempResult = "";
          break;
        case "30012":
          onetopic.TempResult = "";
        case "30014":
          // onetopic.Address = "请选择位置";
          onetopic.longitude = this.location.lng.toString();
          onetopic.lat = this.location.lat.toString();
          // //获取手机经纬度
          // var geolocation = new BMap.Geolocation();
          // geolocation.getCurrentPosition(function (r) {
          //   onetopic.longitude = r.point.lng;
          //   onetopic.lat = r.point.lat;
          // })
          // if (onetopic.longitude == undefined || onetopic.longitude == null || onetopic.longitude == "") {
          //   onetopic.longitude = "126.691392";
          //   onetopic.lat = "45.75136";
          // }
          //  //console.log(onetopic.longitude);
          break;
        case "10012":
          onetopic.TempResult = "";
          break;
        case "10007":
          onetopic.regtemplateActive = true;
          onetopic.regtext = "";
          break;
        case "10017":
          onetopic.listColumn.forEach(onec => {
            onec.Dropdowns = [];
            let temonedq = new DropdownInfo();
            temonedq.FDOptionId = "-1";
            temonedq.FOptionContent = "请选择" + onec.FCOptionContent;
            temonedq.FCSort = 0;
            temonedq.FCid = onec.FCOptionId;
            temonedq.FPid = "-1";
            onec.Dropdowns.push(temonedq);
            if (onec.FSort == 1) {
              onetopic.Dropdowns.forEach(oned => {
                if (oned.FCid == onec.FCOptionId) {
                  onec.Dropdowns.push(oned);
                }
              });
            };
            onec.FTempResult = "-1";
          });
          break;
        case "10018":
          if (onetopic.FselectItemNum == "0") { onetopic.TempResult = ""; }
          else {
            onetopic.listRow.forEach(p => {
              p.testChecked = false;
            })
          }
          break;
        case "10006":
          onetopic.listRow.forEach(p => {
            p.Score = "0";
          });
          ; break;
        case "10005":
          if (onetopic.FAnswerForm == '1000501') {
            onetopic.listRow.forEach(p => {
              p.TemResult = "";
            });
          }
          if (onetopic.FAnswerForm == '1000502') {
            onetopic.listRow.forEach(p => {
              p.listColumn = [];
              onetopic.listColumn.forEach(onec => {
                let tempc = new ColumnInfo();
                tempc.FCOptionAvg = "";
                tempc.FCOptionContent = onec.FCOptionContent;
                tempc.FCOptionId = onec.FCOptionId;
                tempc.FQId = onec.FQId;
                tempc.FSort = onec.FSort;
                tempc.FTopicId = onec.FTopicId;
                tempc.isChecked = "";
                p.listColumn.push(tempc);
              })
            });
          }
          if (onetopic.FAnswerForm == '1000503') {
            onetopic.listRow.forEach(p => {
              p.listColumn = [];
              onetopic.listColumn.forEach(onec => {
                let tempc = new ColumnInfo();
                tempc.FCOptionAvg = "";
                tempc.FCOptionContent = onec.FCOptionContent;
                tempc.FCOptionId = onec.FCOptionId;
                tempc.FQId = onec.FQId;
                tempc.FSort = onec.FSort;
                tempc.FTopicId = onec.FTopicId;
                tempc.TemResult = "";
                tempc.Dropdowns = [];
                let isfirst1000503 = true;//
                onetopic.Dropdowns.forEach(oned => {
                  if (oned.FCSort == onec.FSort) {
                    tempc.Dropdowns.push(oned);
                    //
                    if (isfirst1000503) {
                      tempc.TemResult = oned.FDOptionId;
                    }
                    isfirst1000503 = false;
                  }

                })
                p.listColumn.push(tempc);
              })
            });
          }
          if (onetopic.FAnswerForm == '1000504') {
            //console.log(onetopic)
            onetopic.listRow.forEach(p => {
              p.listColumn = [];
              onetopic.listColumn.forEach(onec => {
                let tempc = new ColumnInfo();
                tempc.FCOptionAvg = "";
                tempc.FCOptionContent = onec.FCOptionContent;
                tempc.FCOptionId = onec.FCOptionId;
                tempc.FQId = onec.FQId;
                tempc.FSort = onec.FSort;
                tempc.FTopicId = onec.FTopicId;
                tempc.TemResult = "";
                tempc.FTempResult = "";
                p.listColumn.push(tempc);
              })
            });
          }
          if (onetopic.FAnswerForm == '1000505') {
            onetopic.listRow.forEach(p => {
              p.listColumn = [];
              onetopic.listColumn.forEach(onec => {
                let tempc = new ColumnInfo();
                tempc.FCOptionAvg = "";
                tempc.FCOptionContent = onec.FCOptionContent;
                tempc.FCOptionId = onec.FCOptionId;
                tempc.FQId = onec.FQId;
                tempc.FSort = onec.FSort;
                tempc.FTopicId = onec.FTopicId;
                tempc.TemResult = "";
                tempc.Dropdowns = [];
                let isfirst1000505 = true;//
                onetopic.Dropdowns.forEach(oned => {
                  if (oned.FCSort == onec.FSort) {
                    tempc.Dropdowns.push(oned);
                    if (isfirst1000505) {
                      tempc.TemResult = oned.FDOptionId;
                    }
                    isfirst1000505 = false;
                  }

                })
                //console.log(55555555555555)
                //console.log(tempc)
                p.listColumn.push(tempc);
              })
            });
          }
          if (onetopic.FAnswerForm == '1000506') {
            onetopic.listRow.forEach(p => {

              p.TemResult = "1";

            });
          }
          ; break;

        case "10011":
          onetopic.listRow.forEach((oner, indexr) => {
            oner.SortQ = indexr;
          });
          break;
        case "10010":
          onetopic.timeyear = "";
          onetopic.timemonth = "";
          onetopic.timeday = "";
          onetopic.timehour = "";
          onetopic.timeminite = "";
          onetopic.timesecond = "";
          break;
        case '10004':
          onetopic.subjectivity = "";
          break;
        case "10003":
          // onetopic.completion.children = ""
          onetopic.strarr10003 = [""];
          break;
        case "10013":
          onetopic.imgs = "";
          break;
        case "10015":
          onetopic.isSelected = "";
          break;
        case "10002":
          onetopic.listRow.forEach(p => {
            p.isChecked = false;
          })
            ; break;
        case "10020":
          onetopic.strarr10020 = [""];
          break;
        case "10016":
          onetopic.listRow.forEach(p => {
            p.TemResult = "0";
            p.TemInput = "0";
          });
      }
    })
    this.topiclist=this.testData.Que.listTopic.filter(p=>p.sjyc==false&&p.FType!="10008");
    // //console.log(listTopic);
  }
  ini10008() {
    let oldtopics = this.testData.Que.listTopic;
    oldtopics.forEach((onet, indext) => {
      if (onet.FType == "10008") {
        let Temptopics10008 = new Array<TopicInfo>();
        oldtopics.forEach((onet8, indext8) => {
          if (onet8.FQuoteTopic == onet.FTopicId) {
            Temptopics10008.push(onet8);
          }
        })
        //
        let TempFTexttypeNum = onet.FTexttypeNum;
        let allcount10008 = Temptopics10008.length;
        let Tempresultarr = this.getRandomArrayElements(Temptopics10008, (allcount10008 - TempFTexttypeNum));
        Tempresultarr.forEach((oneoo, ioo) => {
          oldtopics.forEach((onet8, indext8) => {
            if (onet8.FQuoteTopic == onet.FTopicId) {
              if (oneoo.FTopicId == onet8.FTopicId) {
                 onet8.FShow = false;
                 onet8.sjyc = true;
                // this.testData.Que.listTopic.forEach((oneta, indexta) => {
                //   if(oneta.FTopicId==oneoo.FTopicId){
                //     this.testData.Que.listTopic.splice(indexta,1);
                //   }
                // })
              }
            }
          })
        });
        //
      }
    });
  }
  getRandomArrayElements(arr, count) {
    var shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index;
    while (i-- > min) {
      index = Math.floor((i + 1) * Math.random());
      temp = shuffled[index];
      shuffled[index] = shuffled[i];
      shuffled[i] = temp;
    }
    return shuffled.slice(min);
  }
  ionViewDidLoad() {
    sessionStorage.removeItem("IconTime");
    this.TimeIcon = 'md-play';
    this.TimeText = '暂停';

    let that = this;
    var data = this.navParams.get("resData");
    var id = this.navParams.get("s");
    this._I = this.navParams.get("_i");

    this.Que = data.Que;
    this.res = data.Que.listTopic;
    this.ID = data.Que.FQId;


    this.listRes = data.Que.FTitle;

    if (id == "y") {
      this.y = true;
      this.z = false;
    } else if (id == "z") {
      this.TimeSet();
      this.timebutton();
      this.y = false;
      this.z = true;
    }
  }

  ionViewWillUnload() {
    clearInterval(this.applicationInterval);
    clearInterval(this.buttonInterval);
  }
  timebutton() {//倒计时事件
    this.buttonInterval = setInterval(() => {
      let da = this.GetTime(this._timebutton);
      if (this._timebutton >= 0) {
        this.timesub = da;
        this._timebutton--;
        this._time = this._timebutton
      } else {
        let el = this.subt.nativeElement;
        this.renderer.setStyle(el, 'background', '#c00000');
        this.timesub = "";
      }
    }, 1000);
  }

  TimeSet() {//计时事件
    this.applicationInterval = setInterval(() => {
      let da = this.GetTime(this.receiveDate);
      this.nextBtnText = da;

      this.receiveDate++;
      this.timing = this.receiveDate;

    }, 1000);
  }
  previewDownload() {
    this.navCtrl.push(ListMasterPage, { DataId: this.ID, _I: this._I, x: "x" });
  }

  GetTime(s: number): string {
    let hours = Math.round((s - 30 * 60) / (60 * 60));
    let _hours = hours < 10 ? ('0' + hours) : hours;
    let minutes = Math.round((s - 30) / 60) % 60;
    let _minutes = minutes < 10 ? ('0' + minutes) : minutes;
    let seconds = s % 60;
    let _seconds = seconds < 10 && seconds >= 1 ? ('0' + seconds) : seconds;
    return (hours > 0 ? (_hours + ":") : "00:") + (minutes > 0 ? (_minutes + ":") : "00:") + (seconds > 0 ? (_seconds + "") : "00");
  }

  TimeSuspended() {
    if (sessionStorage.getItem("IconTime") && sessionStorage.getItem("IconTiming")) {
      clearInterval(this.applicationInterval);
      clearInterval(this.buttonInterval);
      this.TimeIcon = 'md-play';
      this.TimeText = "暂停";
      this.show = !this.show;
      this.receiveDate = JSON.parse(sessionStorage.getItem("IconTiming"));//计时
      this._timebutton = JSON.parse(sessionStorage.getItem("IconTime"));//倒计时
      this.TimeSet();
      this.timebutton()
      sessionStorage.removeItem("IconTime");
      sessionStorage.removeItem("IconTiming");
    } else {
      if (this.timing > 1) {
        sessionStorage.setItem("IconTime", JSON.stringify(this._time));//倒计时
        sessionStorage.setItem("IconTiming", JSON.stringify(this.timing));//计时
        this.TimeIcon = 'pause';
        this.TimeText = "开始";
        this.show = !this.show;
        clearInterval(this.applicationInterval);
        clearInterval(this.buttonInterval);
        this.SavePause();
      }
    }
  }
  SavePause() {
    this.saveAswer(-1);
  }



  GetFormDate(now) {
    var year = now.getFullYear(),
      month = now.getMonth() + 1,
      date = now.getDate(),
      hour = now.getHours(),
      minute = now.getMinutes(),
      second = now.getSeconds();

    return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
  }



  guidGenerator() {
    var S4 = function () {
      return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
    };
    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
  }


  testDate;
  //逻辑跳转
  wtjtz(topic) {
    let listTopic = this.testData.Que.listTopic;
    const topictype = topic.FType  //
    const topicsortsort = parseInt(topic.FOrderNum);
    if (topic.FGotoTopic != "" && topic.FGotoTopic != null) {
      //无条件跳转
      if (listTopic.filter(p => p.FTopicId == topic.FGotoTopic) != undefined && listTopic.filter(p => p.FTopicId == topic.FGotoTopic) != null) {
        let gotoTopic = listTopic.filter(p => p.FTopicId == topic.FGotoTopic)[0];
        let gotoIndex = gotoTopic.FOrderNum;
        this.TopicNone(topicsortsort, gotoIndex);
      }
    }
  }

  //选择选项时间，逻辑时间
  pickOption(topic, topicid, optionid, optionContent) {
    let listTopic = this.testData.Que.listTopic;
    const topictype = topic.FType  //
    const topicsortsort = parseInt(topic.FOrderNum);
    if (topic.FGotoTopic != "" && topic.FGotoTopic != null) {
      //无条件跳转
      this.wtjtz(topic);
    }
    else {
      //逻辑跳转
      if (topictype == "10001") {
        let thislistRows = new Array<RowInfo>();
        thislistRows = topic.listRow;
        let thisTempResult = topic.TempResult;
        if (thislistRows.filter(p => p.FROptionId == thisTempResult) != undefined && thislistRows.filter(p => p.FROptionId == thisTempResult) != null) {
          let thisOption = thislistRows.filter(p => p.FROptionId == thisTempResult)[0];
          let istzt = false;

          let skipOptionid = "";
          let skipTopic = "";
          thislistRows.forEach((onerow, index) => {
            //判断逻辑跳转题
            if (onerow.FSkip != "" && onerow.FSkip != "null" && onerow.FSkip != null) {
              skipTopic = onerow.FSkip;
              skipOptionid = onerow.FROptionId;
              istzt = true;
            }
          })
          //
          if (istzt) {
            let gotoTopic = listTopic.filter(p => p.FTopicId == skipTopic)[0];
            let gotoIndex = gotoTopic.FOrderNum;
            if (skipOptionid == topic.TempResult) {
              this.TopicNone(topicsortsort, gotoIndex);
            }
            else {
              this.TopicDisplay(topicsortsort, gotoIndex);
            }
          }
        }
      }
    }
    //隐藏
    if (topictype == "10001") {
      //判断隐藏题
      let isyct = false;
      let thislistRows = new Array<RowInfo>();
      thislistRows = topic.listRow;

      thislistRows.forEach((onerow, indexo) => {
        if (onerow.FROptionId == topic.TempResult) {
          listTopic.forEach((onetopic, indext) => {
            let fsort = onetopic.FOrderNum;
            if (onetopic.FycOpt != null && onetopic.FycOpt != "" && onetopic.FycOpt != "null" && onetopic.FycOpt != undefined) {
              if (onetopic.FycOpt == onerow.FROptionId) {
                onetopic.FShow = true;
              }
            }
          })
        }
        else {
          listTopic.forEach((onetopic, indext) => {
            let fsort = onetopic.FOrderNum;
            if (onetopic.FycOpt != null && onetopic.FycOpt != "" && onetopic.FycOpt != "null" && onetopic.FycOpt != undefined) {
              if (onetopic.FycOpt == onerow.FROptionId) {
                onetopic.FShow = false;
              }
            }
          })
        }
      })
    }
    //题目引用
    listTopic.forEach((onetopic, index) => {
      if (onetopic.FQuoteTopic == topic.FTopicId) {
        onetopic.FTitle = onetopic.FTitleYuan.replace("[-引用位置-]", optionContent);
      }
    })
  }
  //
  TopicNone(startsort, endsort) {
    let listTopic = this.testData.Que.listTopic;
    listTopic.forEach((onetopic, index) => {
      let fsort = onetopic.FOrderNum;
      if (fsort > startsort && fsort < endsort) {
        onetopic.FShow = false;
      }
    })
  }
  //
  TopicDisplay(startsort, endsort) {
    let listTopic = this.testData.Que.listTopic;
    listTopic.forEach((onetopic, index) => {
      let fsort = onetopic.FOrderNum;
      if (fsort > startsort && fsort < endsort) {
        onetopic.FShow = true;
      }
    })
  }
  //检查未作答
  IsComplete() {
    let zcount = 0;//总题数
    let fcount = 0;//非必答题
    let wwccount = 0;//未完成
    let yzdcount = 0//已完成
    let node = new Array<string>();//未完成集合
    //let strAlert = "";
    //检查未作答
    let listTopic = this.testData.Que.listTopic;
    listTopic.forEach((onetopic, index) => {
      //strAlert = "";
      //判断隐藏题型,并且未显示
      let isShow = onetopic.FShow;
      if (isShow) {
        zcount++;
        const topicid = onetopic.FTopicId //
        const topictype = onetopic.FType  //
        const FNeedAnswer = onetopic.FNeedAnswer;
        if (FNeedAnswer == 0) { fcount += 1; return true }
        switch (topictype) {
          case "10001":
            if (onetopic.TempResult == "" || onetopic.TempResult == null || onetopic.TempResult == undefined) {
              wwccount += 1;
              node.push(topicid);
            } else {
              yzdcount += 1;
              // onetopic.Address = "请选择位置";
            };
            break;
          case "30014":
            if (onetopic.Address == "请选择位置" || onetopic.lat == "" || onetopic.lat == undefined) {
              wwccount += 1;
              node.push(topicid);
            } else {
              yzdcount += 1;
            };
            break;

          case "10005":
            if (onetopic.FAnswerForm == '1000504') {
              let text = true;
              onetopic.listRow.forEach((onelist, index) => {
                onelist.listColumn.forEach((onecol, index) => {
                  if (text) {
                    if (onecol.FTempResult == "" || onecol.FTempResult == null || onecol.FTempResult == undefined) {
                      wwccount += 1;
                      node.push(topicid);
                      text = false;
                    }
                  } else {
                    yzdcount += 1;
                  }

                })
              })
            }
            if (onetopic.FAnswerForm == '1000502') {
              let n;
              let che = true;
              n = onetopic.listColumn.length;
              onetopic.listRow.forEach((onelist, index) => {
                let num = 0
                onelist.listColumn.forEach((onecol, index) => {
                  if (che) {
                    if (onecol.isChecked == "" || onecol.isChecked == null || onecol.isChecked == undefined) {
                      num += 1
                      if (n == num) {
                        wwccount += 1;
                        node.push(topicid);
                        che = false;
                      }
                    }
                  } else {
                    yzdcount += 1;
                  }
                })
              })
            }
            if (onetopic.FAnswerForm == '1000501') {
              let sli = true;
              onetopic.listRow.forEach((onelist, index) => {
                if (sli) {
                  if (onelist.TemResult == "" || onelist.TemResult == null || onelist.TemResult == undefined) {
                    wwccount += 1;
                    node.push(topicid);
                    sli = false;
                  }
                } else {
                  yzdcount += 1;
                }
              })
            }
            break;
          case "30012":
            if (onetopic.TempResult == "" || onetopic.TempResult == null || onetopic.TempResult == undefined) {
              wwccount += 1;
              node.push(topicid);
            } else {
              yzdcount += 1;
            };
            break;
          case "10012":
            if (onetopic.TempResult == "" || onetopic.TempResult == null || onetopic.TempResult == undefined) {
              wwccount += 1;
              node.push(topicid);
            } else {
              yzdcount += 1;
            };
            break;
          case "10007":
            if (onetopic.regtext == "" || onetopic.regtext == null || onetopic.regtext == undefined) {
              wwccount += 1;
              node.push(topicid);
            } else {
              yzdcount += 1;
            }
            break;
          case "10017":
            let tempiscomplete10017 = true;
            onetopic.listColumn.forEach(onec => {
              if (onec.FTempResult == undefined || onec.FTempResult == "-1" || onec.FTempResult == null) {
                tempiscomplete10017 = false;
              }
            })
            if (!tempiscomplete10017) {
              wwccount += 1;
              node.push(topicid);
            } else {
              yzdcount += 1;
            }
            ;
            break;
          case "10002":
            let FTextContent10002 = "";
            let tempcount10002 = 0;
            let isComplte10002 = true;
            onetopic.listRow.forEach(onerow => {
              if (onerow.isChecked == true) {
                FTextContent10002 += onerow.FROptionId + "||";
                tempcount10002 += 1;
              }
            });
            if (FTextContent10002 == "" || FTextContent10002 == null || FTextContent10002 == undefined) {
              isComplte10002 = false;
            }
            let FMaxNum = onetopic.FMaxNum;
            let FMinNum = onetopic.FMinNum;
            if ((FMaxNum != null) && (FMaxNum != 0) && (FMaxNum != undefined)) {
              if (FMaxNum < tempcount10002) {
                onetopic.maxmin = "最少选择" + FMinNum + "，最多选择" + FMaxNum;
                isComplte10002 = false;
              }
            }
            if ((FMinNum != null) && (FMinNum != 0) && (FMinNum != undefined)) {
              if (FMinNum > tempcount10002) {
                onetopic.maxmin = "最少选择" + FMinNum + "，最多选择" + FMaxNum;
                isComplte10002 = false;
              }
            }
            if (!isComplte10002) {
              wwccount += 1;
              node.push(topicid);
            } else {
              yzdcount += 1;
            }
            break;
          case "10015":
            if (onetopic.isSelected == "" || onetopic.isSelected == null || onetopic.isSelected == undefined) {
              wwccount += 1;
              node.push(topicid);
            } else {
              yzdcount += 1;
            }
            break;
          case "10013":
            if (onetopic.imgs == "" || onetopic.imgs == null || onetopic.imgs == undefined) {
              wwccount += 1;
              node.push(topicid);
            } else {
              yzdcount += 1;
            }
            break;
          case "10003":
            let thisiscomplete = true;

            for (var i = 0; i < onetopic.completion.children.length; i++) {
              let thisval = onetopic.completion.children[i].value;
              if (thisval == "") {
                thisiscomplete = false;
              }
            }

            if (thisiscomplete == false) {
              wwccount += 1;
              node.push(topicid);
            } else {
              yzdcount += 1;
            }


            break;
          case "10018":
            if (onetopic.FselectItemNum == 0) {
              if (onetopic.TempResult == "" || onetopic.TempResult == null || onetopic.TempResult == undefined) {
                wwccount += 1;
                node.push(topicid);
              } else {
                yzdcount += 1;
              }
            }
            else {
              let FTextContent10018 = "";
              onetopic.listRow.forEach(onerow => {
                if (onerow.testChecked == true) {
                  FTextContent10018 += onerow.FROptionId + "||";
                }
              });
              if (FTextContent10018 == "" || FTextContent10018 == null || FTextContent10018 == undefined) {
                wwccount += 1;
                node.push(topicid);
              } else {
                yzdcount += 1;
              }
            }
            break;

          case "10020":
            let testCompletion = true;

            for (var i = 0; i < onetopic.testCompletion.children.length; i++) {
              let thisval1 = onetopic.testCompletion.children[i].value;

              if (thisval1 == "") {
                testCompletion = false;
              }
            }

            if (!testCompletion) {

              wwccount += 1;
              node.push(topicid);
            } else {
              yzdcount += 1;
            }
            break;
          case "10004":
            if (onetopic.subjectivity == "" || onetopic.subjectivity == null || onetopic.subjectivity == undefined) {
              wwccount += 1;
              node.push(topicid);
            } else {
              yzdcount += 1;
            }
            break;
          case "10010":
            let iscomplete10010 = true;
            //
            onetopic.listRow.forEach(oner => {
              if (oner.FOptionContent.indexOf("year") != -1) {
                if ((onetopic.timeyear == null) || (onetopic.timeyear == "null") || (onetopic.timeyear == undefined) || (onetopic.timeyear == "")) {
                  iscomplete10010 = false;
                }
              }
              if (oner.FOptionContent.indexOf("month") != -1) {
                if ((onetopic.timemonth == null) || (onetopic.timemonth == "null") || (onetopic.timemonth == undefined) || (onetopic.timemonth == "")) {
                  iscomplete10010 = false;
                }
              }
              if (oner.FOptionContent.indexOf("day") != -1) {
                if ((onetopic.timeday == null) || (onetopic.timeday == "null") || (onetopic.timeday == undefined) || (onetopic.timeday == "")) {
                  iscomplete10010 = false;
                }
              }
              if (oner.FOptionContent.indexOf("hour") != -1) {
                if ((onetopic.timehour == null) || (onetopic.timehour == "null") || (onetopic.timehour == undefined) || (onetopic.timehour == "")) {
                  iscomplete10010 = false;
                }
              }
              if (oner.FOptionContent.indexOf("minute") != -1) {
                if ((onetopic.timeminite == null) || (onetopic.timeminite == "null") || (onetopic.timeminite == undefined) || (onetopic.timeminite == "")) {
                  iscomplete10010 = false;
                }
              }
              if (oner.FOptionContent.indexOf("second") != -1) {
                if ((onetopic.timesecond == null) || (onetopic.timesecond == "null") || (onetopic.timesecond == undefined) || (onetopic.timesecond == "")) {
                  iscomplete10010 = false;
                }
              }
            })

            if (!iscomplete10010) {
              wwccount += 1;
              node.push(topicid);
            } else {
              yzdcount += 1;
            }
            break;
        }
      }
    });
    //显示未作答
    if (node.length == 0) {
      return true;
    }
    else {
      this.showUnComplete(node, wwccount);
      this.testData.Que.listTopic.forEach(onet => {
        onet.isComplte = true;
      });
      node.forEach(onen => {
        this.testData.Que.listTopic.forEach(onet => {
          if (onen == onet.FTopicId) {
            onet.isComplte = false;
          }
        })
      });
      return false;
    }

  }
  //显示未作答弹框
  showUnComplete(topicarr: any, wwccount: number) {
    // //console.log(wwccount);
    // //console.log(topicarr);
    const showUnCompletestr = "上有" + wwccount + "道必答题未完成";
    let confirm = this.alertCtrl.create({
      title: showUnCompletestr,
      buttons: [
        {
          text: '取消',
          handler: () => {

          }
        },
        {
          text: '去答题',
          handler: () => {

          }
        }
      ]

    });
    confirm.present();
  }
  // showanswer() {
  //   const localbasefun = this.localbasefun;
  //   localbasefun.getbaseAnswerlogByFQId(this.testData.Que.FQId);
  // }
  submit() {
    if (this._time < 0) {
      this.saveAswer(1);
    } else {
      let toast = this.toastCtrl.create({
        message: "提交时间还没有到！",
        duration: 3000,
        position: 'bottom'
      });
      toast.present();
      return false;
    }
  }
  backpage() {
    // window.history.go(-1);
    this.navCtrl.push("ListMasterPage");
  }
  saveAswer(state) {
    if (state == 1) {
      if (!this.IsComplete()) {
        return;
      }
    }

    let listTopic = this.testData.Que.listTopic;
    let oneAnswerLog = new AnswerLog();
    oneAnswerLog.FQId = this.testData.Que.FQId;
    //获取手机经纬度
    // var geolocation = new BMap.Geolocation();
    // geolocation.getCurrentPosition(function (r) {
    //   oneAnswerLog.Gps = r.point.lng + ',' + r.point.lat;
    // })
    //
    oneAnswerLog.Gps = this.location.lng + ',' + this.location.lat;
    oneAnswerLog.TopicResult = new Array<TopicResultInfo>();
    oneAnswerLog.FTitle = this.testData.Que.FTitle;
    oneAnswerLog.FStartTime = this.GetFormDate(this.thisFStartTime);
    oneAnswerLog.FAnswerId = this.guidGenerator();
    const localbasefun1 = this.localbasefun;
    oneAnswerLog.FPersonId = localbasefun1.getUserId();
    oneAnswerLog.FUpdateloadState = state;
    oneAnswerLog.TopicIdList = new Array<string>();
    oneAnswerLog.FSummitTime = this.GetFormDate(new Date());
    oneAnswerLog.UseTime = this.nextBtnText;
    oneAnswerLog.LastTime = this.timesub;
    oneAnswerLog.FPublishTime = this.testData.Que.FPublishTime;
    //

    listTopic.forEach((onetopic, index) => {
      oneAnswerLog.TopicIdList.push(onetopic.FTopicId);
      //
      let oneTopicResultInfo = new TopicResultInfo();
      oneTopicResultInfo.FTopicId = onetopic.FTopicId;
      oneTopicResultInfo.FTitle = onetopic.FTitle;
      oneTopicResultInfo.FType = onetopic.FType;
      oneTopicResultInfo.FImage = onetopic.FImage;
      oneTopicResultInfo.FAudio = onetopic.FAudio;
      oneTopicResultInfo.FAudioLength = onetopic.FAudioLength;
      oneTopicResultInfo.FShow = onetopic.FShow;
      //
      oneTopicResultInfo.lat = onetopic.lat;
      oneTopicResultInfo.longitude = onetopic.longitude;
      oneTopicResultInfo.Address = onetopic.Address;
      //

      if (onetopic.FType === "10001") {//单选题

        onetopic.listRow.forEach(onerow => {
          if (onetopic.TempResult == onerow.FROptionId) {
            let oneListChildInfo = new ListChildInfo();
            oneListChildInfo.FAnswerChdId = this.guidGenerator();
            oneListChildInfo.FQId = onetopic.FQId;
            oneListChildInfo.FTopicId = onetopic.FTopicId;
            oneListChildInfo.FROptionId = onetopic.TempResult;
            oneListChildInfo.FROptionContent = onerow.FOptionContent;
            oneListChildInfo.FCOptionId = "";
            oneListChildInfo.FCOptionContent = "";
            oneListChildInfo.FType = "10001";
            oneListChildInfo.FTextContent = onetopic.TempResult + "||";
            oneListChildInfo.FTitle = onetopic.FTitle;
            oneListChildInfo.FROptionSort = onerow.FSort.toString();
            oneListChildInfo.FCOptionSort = "";
            oneListChildInfo.FBase64 = "";
            oneListChildInfo.FBase64ID = "";
            oneTopicResultInfo.listChild.push(oneListChildInfo);
          }
        });
      }
      if (onetopic.FType === "30014") {//地图题
        oneAnswerLog.Address = onetopic.Address;
        oneAnswerLog.Gps = onetopic.longitude + "," + onetopic.lat;
      }
      if (onetopic.FType === "30012") {//行业题

        onetopic.listRow.forEach(onerow => {
          if (onetopic.TempResult == onerow.FROptionId) {
            let oneListChildInfo = new ListChildInfo();
            oneListChildInfo.FAnswerChdId = this.guidGenerator();
            oneListChildInfo.FQId = onetopic.FQId;
            oneListChildInfo.FTopicId = onetopic.FTopicId;
            oneListChildInfo.FROptionId = onetopic.TempResult;
            oneListChildInfo.FROptionContent = "";
            oneListChildInfo.FCOptionId = "";
            oneListChildInfo.FCOptionContent = "";
            oneListChildInfo.FType = "30012";
            oneListChildInfo.FTextContent = "";
            oneListChildInfo.FTitle = onetopic.FTitle;
            oneListChildInfo.FROptionSort = "0";
            oneListChildInfo.FCOptionSort = "";
            oneListChildInfo.FBase64 = "";
            oneListChildInfo.FBase64ID = "";
            oneTopicResultInfo.listChild.push(oneListChildInfo);
          }
        });
      }
      if (onetopic.FType === "10012") {//投票题

        onetopic.listRow.forEach(onerow => {
          if (onetopic.TempResult == onerow.FROptionId) {
            let oneListChildInfo = new ListChildInfo();
            oneListChildInfo.FAnswerChdId = this.guidGenerator();
            oneListChildInfo.FQId = onetopic.FQId;
            oneListChildInfo.FTopicId = onetopic.FTopicId;
            oneListChildInfo.FROptionId = onetopic.TempResult;
            oneListChildInfo.FROptionContent = onerow.FOptionContent;
            oneListChildInfo.FCOptionId = "";
            oneListChildInfo.FCOptionContent = "";
            oneListChildInfo.FType = "10012";
            oneListChildInfo.FTextContent = onetopic.TempResult + "||";
            oneListChildInfo.FTitle = onetopic.FTitle;
            oneListChildInfo.FROptionSort = onerow.FSort.toString();
            oneListChildInfo.FCOptionSort = "";
            oneListChildInfo.FBase64 = "";
            oneListChildInfo.FBase64ID = "";
            oneTopicResultInfo.listChild.push(oneListChildInfo);
          }
        });
      }
      if (onetopic.FType === "10011") {//排序题
        onetopic.listRow.forEach(onerow => {
          let oneListChildInfo = new ListChildInfo();
          oneListChildInfo.FAnswerChdId = this.guidGenerator();
          oneListChildInfo.FQId = onetopic.FQId;
          oneListChildInfo.FTopicId = onetopic.FTopicId;
          oneListChildInfo.FROptionId = onerow.FROptionId;
          oneListChildInfo.FROptionContent = onerow.FOptionContent;
          oneListChildInfo.FCOptionId = "";
          oneListChildInfo.FCOptionContent = "";
          oneListChildInfo.FType = "10011";
          oneListChildInfo.FTextContent = onerow.SortQ.toString();
          oneListChildInfo.FTitle = onetopic.FTitle;
          oneListChildInfo.FROptionSort = onerow.FSort.toString();
          oneListChildInfo.FCOptionSort = "";
          oneListChildInfo.FBase64 = "";
          oneListChildInfo.FBase64ID = "";
          oneTopicResultInfo.listChild.push(oneListChildInfo);
        });

      }
      if (onetopic.FType === "10007") {//地区提
        oneTopicResultInfo.TempResult = onetopic.regtext;//临时结果
        //
        let FCOptionContent10007 = "";
        let FTextContent10007 = "";
        let answerarr10007 = onetopic.regtext.split(' ');
        FCOptionContent10007 = answerarr10007[answerarr10007.length - 1];
        //
        if (onetopic.FAnswerForm == "1000701") {
          FTextContent10007 += this.cityColumns[0].options.filter(p => p.value == answerarr10007[0])[0].text;
        }
        if (onetopic.FAnswerForm == "1000702") {
          FTextContent10007 += this.cityColumns[0].options.filter(p => p.value == answerarr10007[0])[0].text + "-";
          FTextContent10007 += this.cityColumns[1].options.filter(p => p.value == answerarr10007[1])[0].text;
        }
        if (onetopic.FAnswerForm == "1000703") {
          FTextContent10007 += this.cityColumns[0].options.filter(p => p.value == answerarr10007[0])[0].text + "-";
          FTextContent10007 += this.cityColumns[1].options.filter(p => p.value == answerarr10007[1])[0].text + "-";
          FTextContent10007 += this.cityColumns[2].options.filter(p => p.value == answerarr10007[2])[0].text;
        }
        //
        FTextContent10007 = FTextContent10007.substring(0, (FTextContent10007.length - 1));
        //
        let oneListChildInfo = new ListChildInfo();
        oneListChildInfo.FAnswerChdId = this.guidGenerator();
        oneListChildInfo.FQId = onetopic.FQId;
        oneListChildInfo.FTopicId = onetopic.FTopicId;
        oneListChildInfo.FROptionId = "";
        oneListChildInfo.FROptionContent = "";
        oneListChildInfo.FCOptionId = onetopic.FAnswerForm;
        oneListChildInfo.FCOptionContent = FTextContent10007;
        oneListChildInfo.FType = "10007";
        oneListChildInfo.FTextContent = FCOptionContent10007;
        oneListChildInfo.FTitle = onetopic.FTitle;
        oneListChildInfo.FROptionSort = "";
        oneListChildInfo.FCOptionSort = "";
        oneListChildInfo.FBase64 = "";
        oneListChildInfo.FBase64ID = "";

        oneTopicResultInfo.listChild.push(oneListChildInfo);


      }
      if (onetopic.FType === "10017") {//联动题
        let TempResult10017 = "";//临时结果
        //
        let FCOptionContent10017 = "";
        let FTextContent10017 = "";
        onetopic.listColumn.forEach((onec, indexc) => {
          onetopic.Dropdowns.forEach(oned => {
            if (oned.FDOptionId == onec.FTempResult) {
              if (onec.FSort == 1) {
                FTextContent10017 += oned.FOptionContent;
                TempResult10017 += oned.FDOptionId;
              }
              else {
                FTextContent10017 += "-" + oned.FOptionContent;
                TempResult10017 += "-" + oned.FDOptionId;
              }
            }
          });
          if (indexc == (onetopic.listColumn.length - 1)) {
            FTextContent10017 = onec.FTempResult;
          }
        })
        //
        oneTopicResultInfo.TempResult = TempResult10017;
        //
        let oneListChildInfo = new ListChildInfo();
        oneListChildInfo.FAnswerChdId = this.guidGenerator();
        oneListChildInfo.FQId = onetopic.FQId;
        oneListChildInfo.FTopicId = onetopic.FTopicId;
        oneListChildInfo.FROptionId = "";
        oneListChildInfo.FROptionContent = "";
        oneListChildInfo.FCOptionId = onetopic.FAnswerForm;
        oneListChildInfo.FCOptionContent = FTextContent10017;
        oneListChildInfo.FType = "10007";
        oneListChildInfo.FTextContent = FCOptionContent10017;
        oneListChildInfo.FTitle = onetopic.FTitle;
        oneListChildInfo.FROptionSort = "";
        oneListChildInfo.FCOptionSort = "";
        oneListChildInfo.FBase64 = "";
        oneListChildInfo.FBase64ID = "";

        oneTopicResultInfo.listChild.push(oneListChildInfo);


      }
      if (onetopic.FType === "10002") {
        let FTextContent10002 = "";
        onetopic.listRow.forEach(onerow => {
          if (onerow.isChecked == true) {
            FTextContent10002 += onerow.FROptionId + "||";
          }
        });
        onetopic.listRow.forEach(onerow => {
          if (onerow.isChecked == true) {
            let oneListChildInfo = new ListChildInfo();
            oneListChildInfo.FAnswerChdId = this.guidGenerator();
            oneListChildInfo.FQId = onetopic.FQId;
            oneListChildInfo.FTopicId = onerow.FTopicId;
            oneListChildInfo.FROptionId = onerow.FROptionId;
            oneListChildInfo.FROptionContent = onerow.FOptionContent;
            oneListChildInfo.FCOptionId = "";
            oneListChildInfo.FCOptionContent = "";
            oneListChildInfo.FType = "10002";
            oneListChildInfo.FTextContent = FTextContent10002;
            oneListChildInfo.FTitle = onetopic.FTitle;
            oneListChildInfo.FROptionSort = onerow.FSort.toString();
            oneListChildInfo.FCOptionSort = "";
            oneListChildInfo.FBase64 = "";
            oneListChildInfo.FBase64ID = "";
            oneTopicResultInfo.listChild.push(oneListChildInfo);
          }
        })
      }
      if (onetopic.FType == "10015") {
        onetopic.listRow.forEach(onerow => {
          if (onetopic.isSelected == onerow.FROptionId) {
            let oneListChildInfo = new ListChildInfo();
            oneListChildInfo.FAnswerChdId = this.guidGenerator();
            oneListChildInfo.FQId = onetopic.FQId;
            oneListChildInfo.FTopicId = onetopic.FTopicId;
            oneListChildInfo.FROptionId = onerow.FROptionId;
            oneListChildInfo.FROptionContent = onetopic.isSelected;
            oneListChildInfo.FCOptionId = "";
            oneListChildInfo.FCOptionContent = "";
            oneListChildInfo.FType = "10015";
            oneListChildInfo.FTextContent = onetopic.isSelected + "||";
            oneListChildInfo.FTitle = onetopic.FTitle;
            oneListChildInfo.FROptionSort = onerow.FSort.toString();
            oneListChildInfo.FCOptionSort = "";
            oneListChildInfo.FBase64 = "";
            oneListChildInfo.FBase64ID = "";
            oneTopicResultInfo.listChild.push(oneListChildInfo);
            //console.log(oneTopicResultInfo)
          }
        })
      }
      if (onetopic.FType === "10013") {

        onetopic.listRow.forEach(onerow => {

          if (onetopic.imgs == onerow.FROptionId) {
            let oneListChildInfo = new ListChildInfo();
            oneListChildInfo.FAnswerChdId = this.guidGenerator();
            oneListChildInfo.FQId = onetopic.FQId;
            oneListChildInfo.FTopicId = onerow.FTopicId;
            oneListChildInfo.FROptionId = onerow.FROptionId;
            oneListChildInfo.FROptionContent = onerow.FOptionContent;
            oneListChildInfo.FCOptionId = "";
            oneListChildInfo.FCOptionContent = "";
            oneListChildInfo.FType = "10013";
            oneListChildInfo.FTextContent = onetopic.imgs + "||";
            oneListChildInfo.FTitle = onetopic.FTitle;
            oneListChildInfo.FROptionSort = onerow.FSort.toString();
            oneListChildInfo.FBase64 = "";
            oneListChildInfo.FBase64ID = onerow.FBase64;
            oneTopicResultInfo.listChild.push(oneListChildInfo);
          }
        });
      }
      if (onetopic.FType === "10003") {
        let val = "";
        for (var i = 0; i < onetopic.completion.children.length; i++) {
          val += onetopic.completion.children[i].value + "||";
        }

        let oneListChildInfo = new ListChildInfo();
        oneListChildInfo.FAnswerChdId = this.guidGenerator();
        oneListChildInfo.FQId = onetopic.FQId;
        oneListChildInfo.FTopicId = onetopic.FTopicId;
        oneListChildInfo.FROptionId = "";
        oneListChildInfo.FROptionContent = "";
        oneListChildInfo.FCOptionId = "";
        oneListChildInfo.FCOptionContent = "";
        oneListChildInfo.FType = "10003";
        oneListChildInfo.FTextContent = val;
        oneListChildInfo.FTitle = "";
        oneListChildInfo.FROptionSort = "";
        oneListChildInfo.FCOptionSort = "";
        oneListChildInfo.FBase64 = "";
        oneListChildInfo.FBase64ID = "";
        oneTopicResultInfo.listChild.push(oneListChildInfo);
      }
      if (onetopic.FType === "10018" && onetopic.FselectItemNum == 0) {//测试单选
        onetopic.listRow.forEach(onerow => {
          if (onetopic.TempResult == onerow.FROptionId) {
            let oneListChildInfo = new ListChildInfo();
            oneListChildInfo.FAnswerChdId = this.guidGenerator();
            oneListChildInfo.FQId = onetopic.FQId;
            oneListChildInfo.FTopicId = onetopic.FTopicId;
            oneListChildInfo.FROptionId = onetopic.TempResult;
            oneListChildInfo.FROptionContent = onerow.FOptionContent;
            oneListChildInfo.FCOptionId = "";
            oneListChildInfo.FCOptionContent = "";
            oneListChildInfo.FType = "10018";
            oneListChildInfo.FTextContent = onetopic.TempResult + "||";
            oneListChildInfo.FTitle = onetopic.FTitle;
            oneListChildInfo.FROptionSort = onerow.FSort.toString();
            oneListChildInfo.FCOptionSort = "";
            oneListChildInfo.FBase64 = "";
            oneListChildInfo.FBase64ID = "";
            oneTopicResultInfo.listChild.push(oneListChildInfo);
          }
        });

      }
      if (onetopic.FType === "10018" && onetopic.FselectItemNum == 1) {
        let FTextContent10018 = "";
        onetopic.listRow.forEach(onerow => {
          if (onerow.testChecked == true) {
            FTextContent10018 += onerow.FROptionId + "||";
          }
        });
        onetopic.listRow.forEach(onerow => {
          if (onerow.testChecked == true) {
            let oneListChildInfo = new ListChildInfo();
            oneListChildInfo.FAnswerChdId = this.guidGenerator();
            oneListChildInfo.FQId = onerow.FQId;
            oneListChildInfo.FTopicId = onerow.FTopicId;
            oneListChildInfo.FROptionId = onerow.FROptionId;
            oneListChildInfo.FROptionContent = onerow.FOptionContent;
            oneListChildInfo.FCOptionId = "";
            oneListChildInfo.FCOptionContent = "";
            oneListChildInfo.FType = "10018";
            oneListChildInfo.FTextContent = FTextContent10018;
            oneListChildInfo.FTitle = onetopic.FTitle;
            oneListChildInfo.FROptionSort = onerow.FSort.toString();
            oneListChildInfo.FCOptionSort = "";
            oneListChildInfo.FBase64 = "";
            oneListChildInfo.FBase64ID = "";
            oneTopicResultInfo.listChild.push(oneListChildInfo);

          }

        });
      }
      if (onetopic.FType === "10020") {
        let val1 = "";
        for (var j = 0; j < onetopic.testCompletion.children.length; j++) {
          val1 += onetopic.testCompletion.children[j].value + "||";
        }
        let oneListChildInfo = new ListChildInfo();
        oneListChildInfo.FAnswerChdId = this.guidGenerator();
        oneListChildInfo.FQId = onetopic.FQId;
        oneListChildInfo.FTopicId = onetopic.FTopicId;
        oneListChildInfo.FROptionId = "";
        oneListChildInfo.FROptionContent = "";
        oneListChildInfo.FCOptionId = "";
        oneListChildInfo.FCOptionContent = "";
        oneListChildInfo.FType = "10020";
        oneListChildInfo.FTextContent = val1;
        oneListChildInfo.FTitle = "";
        oneListChildInfo.FROptionSort = "";
        oneListChildInfo.FCOptionSort = "";
        oneListChildInfo.FBase64 = "";
        oneListChildInfo.FBase64ID = "";
        oneTopicResultInfo.listChild.push(oneListChildInfo);
      }
      if (onetopic.FType === "10004") {
        let oneListChildInfo = new ListChildInfo();
        oneListChildInfo.FAnswerChdId = this.guidGenerator();
        oneListChildInfo.FQId = onetopic.FQId;
        oneListChildInfo.FTopicId = onetopic.FTopicId;
        oneListChildInfo.FROptionId = "";
        oneListChildInfo.FROptionContent = "";
        oneListChildInfo.FCOptionId = "";
        oneListChildInfo.FCOptionContent = "";
        oneListChildInfo.FType = "10004";
        oneListChildInfo.FTextContent = onetopic.subjectivity;

        oneListChildInfo.FTitle = onetopic.FTitle;
        oneListChildInfo.FROptionSort = "";
        oneListChildInfo.FCOptionSort = "";
        oneListChildInfo.FBase64 = "";
        oneListChildInfo.FBase64ID = "";
        oneTopicResultInfo.listChild.push(oneListChildInfo);

      }
      if (onetopic.FType === "10010") {

        // this.time.push(onetopic.timeyear, onetopic.timemonth, onetopic.timeday, onetopic.timehour, onetopic.timeminite, onetopic.timesecond);
        console.log(this.time)

        var value = "";

        if (onetopic.timeyear && onetopic.timeyear != undefined) {
          value += (onetopic.timeyear < 10 ? "0" + onetopic.timeyear + "年||" : onetopic.timeyear + "年||");
        }
        if (onetopic.timemonth && onetopic.timemonth != undefined) {
          value += (onetopic.timemonth < 10 ? "0" + onetopic.timemonth + "月||" : onetopic.timemonth + "月||");
        }
        if (onetopic.timeday && onetopic.timeday != undefined) {
          value += (onetopic.timeday < 10 ? "0" + onetopic.timeday + "日||" : onetopic.timeday + "日||");
        }
        if (onetopic.timehour && onetopic.timehour != undefined) {
          value += (onetopic.timehour < 10 ? "0" + onetopic.timehour + "时||" : onetopic.timehour + "时||");
        }
        if (onetopic.timeminite && onetopic.timeminite != undefined) {
          value += (onetopic.timeminite < 10 ? "0" + onetopic.timeminite + "分||" : onetopic.timeminite + "分||");
        }
        if (onetopic.timesecond && onetopic.timesecond != undefined) {
          value += (onetopic.timesecond < 10 ? "0" + onetopic.timesecond + "秒||" : onetopic.timesecond + "秒||");
        }

        let oneListChildInfo = new ListChildInfo();
        onetopic.listRow.forEach(onerow => {
          oneListChildInfo.FAnswerChdId = this.guidGenerator();
          oneListChildInfo.FQId = onetopic.FQId;
          oneListChildInfo.FTopicId = onetopic.FTopicId;
          oneListChildInfo.FROptionId = "";
          oneListChildInfo.FROptionContent = onerow.FOptionContent;
          oneListChildInfo.FCOptionId = "";
          oneListChildInfo.FCOptionContent = "";
          oneListChildInfo.FType = "10010";
          oneListChildInfo.FTextContent = value;
          oneListChildInfo.FTitle = onetopic.FTitle;
          oneListChildInfo.FROptionSort = "";
          oneListChildInfo.FCOptionSort = "";
          oneListChildInfo.FBase64 = "";
          oneListChildInfo.FBase64ID = "";
          oneTopicResultInfo.listChild.push(oneListChildInfo);
        })
      }
      if (onetopic.FType === "10006") {
        // let oneTopicResultInfo = new TopicResultInfo();
        // oneTopicResultInfo.FTopicId = onetopic.FTopicId;
        // oneTopicResultInfo.FTitle = onetopic.FTitle;
        // oneTopicResultInfo.FType = onetopic.FType;
        // oneTopicResultInfo.FImage = "";
        // oneTopicResultInfo.FAudio = "";
        onetopic.listRow.forEach(onerow => {
          let oneListChildInfo = new ListChildInfo();
          oneListChildInfo.FAnswerChdId = this.guidGenerator();
          oneListChildInfo.FQId = onetopic.FQId;
          oneListChildInfo.FTopicId = onetopic.FTopicId;
          oneListChildInfo.FROptionId = onerow.FROptionId;
          oneListChildInfo.FROptionContent = onerow.FOptionContent;
          oneListChildInfo.FCOptionId = "";
          oneListChildInfo.FCOptionContent = "";
          oneListChildInfo.FType = "10006";
          oneListChildInfo.FTextContent = onerow.Score.toString();
          oneListChildInfo.FTitle = onetopic.FTitle;
          oneListChildInfo.FROptionSort = onerow.FSort.toString();
          oneListChildInfo.FCOptionSort = "";
          oneListChildInfo.FBase64 = "";
          oneListChildInfo.FBase64ID = "";
          oneTopicResultInfo.listChild.push(oneListChildInfo);
          // //console.log(oneListChildInfo.FTextContent)

        });

      }
      if (onetopic.FType === "10005") {
        if (onetopic.FAnswerForm == '1000501') {

          onetopic.listRow.forEach(onerow => {
            //
            // onerow.listColumn.forEach(ccc=>{
            //   if(ccc.isChecked==true)
            //   {
            //     oneListChildInfo.FROptionSort=onerow.FSort;
            //     oneListChildInfo.FCOptionSort=col;
            //   }
            // })
            //
            let row;
            let col;
            if (onerow.TemResult) {
              onerow.TemResult.split(".")
              row = onerow.TemResult.split(".")[0];
              col = onerow.TemResult.split(".")[1];
            }
            let oneListChildInfo = new ListChildInfo();
            oneListChildInfo.FAnswerChdId = this.guidGenerator();
            oneListChildInfo.FQId = onetopic.FQId;
            oneListChildInfo.FTopicId = onetopic.FTopicId;
            oneListChildInfo.FROptionId = onerow.FROptionId;
            oneListChildInfo.FROptionContent = onerow.FOptionContent;
            oneListChildInfo.FCOptionId = "";
            oneListChildInfo.FCOptionContent = "";
            oneListChildInfo.FType = "10005";
            oneListChildInfo.FTextContent = "";
            oneListChildInfo.FTitle = onetopic.FTitle;
            oneListChildInfo.FROptionSort = row;
            oneListChildInfo.FCOptionSort = col;
            oneListChildInfo.FBase64 = "";
            oneListChildInfo.FBase64ID = "";
            oneTopicResultInfo.listChild.push(oneListChildInfo);
            // //console.log(oneListChildInfo.FTextContent)
            return false;
          });
        }
        if (onetopic.FAnswerForm == '1000502') {
          onetopic.listRow.forEach(onerow => {
            onerow.listColumn.forEach(item => {
              if (item.isChecked) {
                let oneListChildInfo = new ListChildInfo();
                oneListChildInfo.FAnswerChdId = this.guidGenerator();
                oneListChildInfo.FQId = onetopic.FQId;
                oneListChildInfo.FTopicId = onetopic.FTopicId;
                oneListChildInfo.FROptionId = onerow.FROptionId;
                oneListChildInfo.FROptionContent = onerow.FOptionContent;
                oneListChildInfo.FCOptionId = "";
                oneListChildInfo.FCOptionContent = "";
                oneListChildInfo.FType = "10005";
                oneListChildInfo.FTextContent = "";
                oneListChildInfo.FTitle = onetopic.FTitle;
                oneListChildInfo.FROptionSort = onerow.FSort.toString();
                oneListChildInfo.FCOptionSort = item.FSort.toString();
                oneListChildInfo.FBase64 = "";
                oneListChildInfo.FBase64ID = "";
                oneTopicResultInfo.listChild.push(oneListChildInfo);
                // //console.log(oneListChildInfo.FTextContent)
                return false;
              }
            })

          });
          //console.log(999999999999999)
          //console.log(oneTopicResultInfo)
        }
        if (onetopic.FAnswerForm == '1000503') {
          onetopic.listRow.forEach(onerow => {
            onerow.listColumn.forEach(itemc => {
              let data = itemc.TemResult;
              let oneListChildInfo = new ListChildInfo();
              oneListChildInfo.FAnswerChdId = this.guidGenerator();
              oneListChildInfo.FQId = onetopic.FQId;
              oneListChildInfo.FTopicId = onetopic.FTopicId;
              oneListChildInfo.FROptionId = onerow.FROptionId;
              oneListChildInfo.FROptionContent = onerow.FOptionContent;
              oneListChildInfo.FCOptionId = "";
              oneListChildInfo.FCOptionContent = "";
              oneListChildInfo.FType = "10005";
              oneListChildInfo.FTextContent = data;
              oneListChildInfo.FTitle = onetopic.FTitle;
              oneListChildInfo.FROptionSort = onerow.FSort.toString();
              oneListChildInfo.FCOptionSort = itemc.FSort.toString();
              oneListChildInfo.FBase64 = "";
              oneListChildInfo.FBase64ID = "";
              oneTopicResultInfo.listChild.push(oneListChildInfo);
            })

          });
        }
        if (onetopic.FAnswerForm == '1000504') {
          onetopic.listRow.forEach(onerow => {
            onerow.listColumn.forEach(itemc => {
              let data = itemc.FTempResult;
              let oneListChildInfo = new ListChildInfo();
              oneListChildInfo.FAnswerChdId = this.guidGenerator();
              oneListChildInfo.FQId = onetopic.FQId;
              oneListChildInfo.FTopicId = onetopic.FTopicId;
              oneListChildInfo.FROptionId = onerow.FROptionId;
              oneListChildInfo.FROptionContent = onerow.FOptionContent;
              oneListChildInfo.FCOptionId = "";
              oneListChildInfo.FCOptionContent = "";
              oneListChildInfo.FType = "10005";
              oneListChildInfo.FTextContent = data;
              oneListChildInfo.FTitle = onetopic.FTitle;
              oneListChildInfo.FROptionSort = onerow.FSort.toString();
              oneListChildInfo.FCOptionSort = itemc.FSort.toString();
              oneListChildInfo.FBase64 = "";
              oneListChildInfo.FBase64ID = "";
              oneTopicResultInfo.listChild.push(oneListChildInfo);
            })
          });
        }
        if (onetopic.FAnswerForm == '1000505') {
          onetopic.listRow.forEach(onerow => {
            onerow.listColumn.forEach(itemc => {
              let data = itemc.TemResult;
              let oneListChildInfo = new ListChildInfo();
              oneListChildInfo.FAnswerChdId = this.guidGenerator();
              oneListChildInfo.FQId = onetopic.FQId;
              oneListChildInfo.FTopicId = onetopic.FTopicId;
              oneListChildInfo.FROptionId = onerow.FROptionId;
              oneListChildInfo.FROptionContent = onerow.FOptionContent;
              oneListChildInfo.FCOptionId = "";
              oneListChildInfo.FCOptionContent = "";
              oneListChildInfo.FType = "10005";
              oneListChildInfo.FTextContent = data;
              oneListChildInfo.FTitle = onetopic.FTitle;
              oneListChildInfo.FROptionSort = onerow.FSort.toString();
              oneListChildInfo.FCOptionSort = itemc.FSort.toString();
              oneListChildInfo.FBase64 = "";
              oneListChildInfo.FBase64ID = "";
              oneTopicResultInfo.listChild.push(oneListChildInfo);
            })
          });
        }
        if (onetopic.FAnswerForm == '1000506') {
          onetopic.listRow.forEach(onerow => {
            let row;
            let col;
            if (onerow.TemResult) {

              // onerow.TemResult.split(".")
              // row=onerow.TemResult.split(".")[0];
              // col=onerow.TemResult.split(".")[1];
            }
            let oneListChildInfo = new ListChildInfo();
            oneListChildInfo.FAnswerChdId = this.guidGenerator();
            oneListChildInfo.FQId = onetopic.FQId;
            oneListChildInfo.FTopicId = onetopic.FTopicId;
            oneListChildInfo.FROptionId = onerow.FROptionId;
            oneListChildInfo.FROptionContent = onerow.FOptionContent;
            oneListChildInfo.FCOptionId = "";
            oneListChildInfo.FCOptionContent = "";
            oneListChildInfo.FType = "10005";
            oneListChildInfo.FTextContent = onerow.TemResult;
            oneListChildInfo.FTitle = onetopic.FTitle;
            oneListChildInfo.FROptionSort = onerow.FSort.toString();
            oneListChildInfo.FCOptionSort = onerow.TemResult.toString();
            oneListChildInfo.FBase64 = "";
            oneListChildInfo.FBase64ID = "";
            oneTopicResultInfo.listChild.push(oneListChildInfo);
            // //console.log(oneListChildInfo.FTextContent)
            return false;
          });
          //console.log(oneTopicResultInfo)
        }

      }
      if (onetopic.FType == '10016') {
        onetopic.listRow.forEach(onerow => {
          let oneListChildInfo = new ListChildInfo();
          oneListChildInfo.FAnswerChdId = this.guidGenerator();
          oneListChildInfo.FQId = onetopic.FQId;
          oneListChildInfo.FTopicId = onetopic.FTopicId;
          oneListChildInfo.FROptionId = onerow.FROptionId;
          oneListChildInfo.FROptionContent = onerow.FOptionContent;
          oneListChildInfo.FCOptionId = "";
          oneListChildInfo.FCOptionContent = "";
          oneListChildInfo.FType = "10016";
          oneListChildInfo.FTextContent = onerow.TemResult;
          oneListChildInfo.FTitle = onetopic.FTitle;
          oneListChildInfo.FROptionSort = onerow.FSort.toString();
          oneListChildInfo.FCOptionSort = "";
          oneListChildInfo.FBase64 = "";
          oneListChildInfo.FBase64ID = "";
          oneTopicResultInfo.listChild.push(oneListChildInfo);
          // //console.log(oneListChildInfo.FTextContent)
          return false;
        });
        // //console.log(999999999999999)
        // //console.log(oneTopicResultInfo)
      }
      oneAnswerLog.TopicResult.push(oneTopicResultInfo);
    });
    let confirm = this.alertCtrl.create({
      title: '是否跳转至回收页',
      buttons: [
        {
          text: '取消',
          handler: () => {

          }
        },
        {
          text: '确定',
          handler: async () => {
            const localbasefun = this.localbasefun;
            console.log(oneAnswerLog);
            await localbasefun.setbaseAnswerlog(oneAnswerLog.FAnswerId, oneAnswerLog.FQId, oneAnswerLog.FPublishTime, oneAnswerLog);
            await localbasefun.QueNumPlusOne(oneAnswerLog.FQId, oneAnswerLog.FPublishTime);
            this.navCtrl.pop();
            this.navCtrl.push('RecyclingPage', { fqid: this.testData.Que.FQId, state, statedata: state });
            sessionStorage.setItem('recycfqid', this.testData.Que.FQId);
            //自动上传

            if (state == 1) {
              let tempdata = new AnswerLogUp();
              tempdata.FQId = oneAnswerLog.FQId;
              tempdata.FTitle = oneAnswerLog.FTitle;
              tempdata.FStartTime = oneAnswerLog.FStartTime;
              tempdata.FAnswerId = oneAnswerLog.FAnswerId;
              tempdata.FUpdateloadState = oneAnswerLog.FUpdateloadState;
              tempdata.Gps = oneAnswerLog.Gps;
              tempdata.FSummitTime = oneAnswerLog.FSummitTime;
              //  const localbasefun1=this.localbasefun;
              tempdata.FPersonId = oneAnswerLog.FPersonId;
              tempdata.TopicIdList = oneAnswerLog.TopicIdList;
              //
              tempdata.listTopic = new Array<MobileAnswer>();
              //
              let topiclist = oneAnswerLog.TopicResult;
              topiclist.forEach((onetopic, indext) => {
                if (onetopic.FShow) {
                  let oneMobileAnswer = new MobileAnswer("", "", "", [], 0, "", "");
                  oneMobileAnswer.FTopicId = onetopic.FTopicId;
                  oneMobileAnswer.FTitle = onetopic.FTitle;
                  oneMobileAnswer.FType = onetopic.FType;
                  oneMobileAnswer.FSoundDuration = onetopic.FAudioLength;
                  oneMobileAnswer.FSoundData = onetopic.FAudio;
                  oneMobileAnswer.ImgData = onetopic.FImage;
                  //
                  oneMobileAnswer.longitude = onetopic.longitude;
                  oneMobileAnswer.lat = onetopic.lat;
                  oneMobileAnswer.Address = onetopic.Address;
                  //
                  oneMobileAnswer.listChild = new Array<MobileAnserChd>();
                  //
                  onetopic.listChild.forEach(onelistChild => {
                    let oneMobileAnserChd = new MobileAnserChd();
                    oneMobileAnserChd.FAnswerChdId = onelistChild.FAnswerChdId;
                    oneMobileAnserChd.FQId = onelistChild.FQId;
                    oneMobileAnserChd.FTopicId = onelistChild.FTopicId;
                    oneMobileAnserChd.FROptionId = onelistChild.FROptionId;
                    oneMobileAnserChd.FROptionContent = onelistChild.FROptionContent;
                    oneMobileAnserChd.FCOptionId = onelistChild.FCOptionId;
                    oneMobileAnserChd.FCOptionContent = onelistChild.FCOptionContent;
                    oneMobileAnserChd.FType = onelistChild.FType;
                    oneMobileAnserChd.FTextContent = onelistChild.FTextContent;
                    oneMobileAnserChd.FTitle = onelistChild.FTitle;
                    oneMobileAnserChd.FROptionSort = onelistChild.FROptionSort;
                    oneMobileAnserChd.FCOptionSort = onelistChild.FCOptionSort;
                    oneMobileAnserChd.FBase64 = onelistChild.FBase64;
                    //
                    oneMobileAnswer.listChild.push(oneMobileAnserChd);
                  });
                  //
                  tempdata.listTopic.push(oneMobileAnswer);
                }
              });
              if (this.localbasefun.getAutoSc() === 'Auto') {
                //上传
                const code = await this.api.addMobileAnswer(tempdata);
                if (code && code.message === '上传成功') {
                  // //改变作答状态
                  await this.localbasefun.changeAnswerState(oneAnswerLog.FAnswerId, oneAnswerLog.FQId, oneAnswerLog.FPublishTime, 2);
                } else {
                  let toast = this.toastCtrl.create({
                    message: "上传失败",
                    duration: 1000,
                    position: 'top'
                  });
                  toast.present();
                }
              }
            }
          }
        }
      ]
    });
    confirm.present();
  }



  ionViewWillEnter() {


    //进入去掉tab
    let elements = document.querySelectorAll(".tabbar");
    if (elements != null) {
      Object.keys(elements).map((key) => {
        elements[key].style.display = 'none';
      });
    }
  }


  ionViewWillLeave() {
    let elements = document.querySelectorAll(".tabbar");
    if (elements != null) {
      Object.keys(elements).map((key) => {
        elements[key].style.display = 'flex';
      });
    }
  }
}
